<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>成员信息</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    <c:import url="tea_home.jsp"></c:import>
    <!-- 页面内容 -->
     	<div class="layui-body container" style="margin-top: 100px">
     		<!-- 搜索框 -->
     		<div class="layui-row" >
     			<form class="layui-form" action="${pageContext.request.contextPath}/admin/teaInfo.do" method="post">
     				<div class="layui-form-item">
					  	<div class="layui-input-inline layui-col-md-offset2 layui-col-md4">
					     	<input type="text" id="stuName" name="stuName" lay-verify="required" placeholder="输入学生姓名" autocomplete="off" class="layui-input">
					     </div>
					     <div class="layui-col-md4">
					     <button type="button" class="btn btn-info">查询</button>
					     </div>
					</div>
				</form>
			</div>
			
     		<!-- 显示表格数据 -->
     		<div class="layui-row">
     			<div class="layui-col-md-offset1 layui-col-md11">
     				<table class="table table-hover" id="memberTable">
     					<thead>
     					<tr>
     						<th>ID</th>
     						<th>学号</th>
     						<th>姓名</th>
     						<th>班级</th>
     						
     						<th>联系方式</th>
     						<th>项目名称</th>
     						<th>Gitee主页</th>
     						<th>项目状态</th>
     						<th>任务名称</th>
     						<th>操作</th>
     					</tr>
     					</thead>
     					<tbody>
     					
     					</tbody>
     					</table>
     			</div>
     		</div>
     		
     		<!-- 分页条 -->
     		<div class="layui-row">
     			<div class="layui-col-md-offset1 layui-col-md3" id="page_info_area">
     			</div>
     			<div class="col-md-5" id="page_info_nav">
     			</div>
     		</div>
     </div>
<script type="text/javascript">
	var index_id=1;
	$(function(){
		toPage(1);
	});
	function toPage(pn){
		$.ajax({
			url:"${pageContext.request.contextPath}/teacher/getMemberInfo.do",
			data:"pageNum="+pn,
			type:"GET",
			success:function(result){
				console.log(result);
				
				//1.解析并显示数据
				build_tableInfo(result);
				//2.解析显示分页信息
				build_pageInfo(result);
				build_page_nav(result);
				
			}
		});
	}
	//解析显示分页信息
    function build_tableInfo(result){
    	$("#memberTable tbody").empty();
    	var memberPOJO=result.extend.page.list[0];
    	console.log("memberPOJO:"+memberPOJO);
    	if(memberPOJO==null){
    		$("#memberTable tbody").append("没有数据");
    		return;
    	}
    	var projectName=$("<td></td>").append(memberPOJO.projectName);
    	
    	
    	console.log(memberPOJO.members);

    	$.each(memberPOJO.members,function(index,member){
    		console.log(member);
    		console.log(index);
    		var id=$("<td></td>").append(index+1);
    		var stuId=$("<td></td>").append(member.stuId);
    		var stuName=$("<td></td>").append(member.stuName);
    		var stuClass=$("<td></td>").append(member.stuClass);
    		//var stuEmail=$("<td></td>").append(member.stuEmail);
    		var stuTell=$("<td></td>").append(member.stuTell);
    		var projectName=$("<td></td>").append(memberPOJO.projectName);
    		var giteePage=$("<td></td>").append($("<a></a>").attr("href","javascrip:void(0)").attr("onclick","visitGitee("+member.stuId+")").append("访问"));
    		var status=memberPOJO.projectStatus;
        	var ststus_val;
        	if(status==0){
        		ststus_val="验收完成";
        	}else if(status==1){
        		ststus_val="申报成功";
        	}else if(status==2){
        		ststus_val="提交需求";
        	}else if(status==3){
        		ststus_val="代码完成0%";
        	}else if(status==4){
        		ststus_val="代码完成20%";
        	}else if(status==5){
        		ststus_val="代码完成40%";
        	}else if(status==6){
        		ststus_val="代码完成60%";
        	}else if(status==7){
        		ststus_val="代码完成80%";
        	}else if(status==8){
        		ststus_val="代码完成100%";
        	}else if(status==9){
        		ststus_val="软件测试";
        	}else if(status==10){
        		ststus_val="申请验收";
        	}
        	var projectStatus=$("<td></td>").append(ststus_val);
    		var taskName=$("<td></td>").append(member.memberStatus==0?"未分配":"已分配");
    		var edit=$("<td></td>");
    		var delete_edit=$("<a></a>").attr("href","${pageContext.request.contextPath}/teacher/deleteMember.do?groupId="+memberPOJO.groupId+"&stuId="+member.stuId)
    						.append($("<i></i>").addClass("layui-icon").attr("style","font-size: 20px;").append("&#xe640;")).append("删除");
    		if(member.memberStatus==0){
    			edit.append(delete_edit);
    		}else{
    			var url=$("<a></a>").append("查看代码提交情况").attr("href","javascrip:vid(0)").attr("onclick","showGiteePush("+member.stuId+","+memberPOJO.projectId+")");
    			edit.append(url);
    		}
    		$("<tr></tr>").append(id).append(stuId).append(stuName).append(stuClass)
    					.append(stuTell).append(projectName).append(giteePage).append(projectStatus).append(taskName).append(edit)
    					.appendTo("#memberTable tbody");
    	});
    }
  	//解析显示分页信息
    var currentPage;
    function build_pageInfo(result){
    	$("#page_info_area").empty();
    	currentPage=result.extend.page.pageNum;
    	$("#page_info_area").append("当前"+result.extend.page.pageNum+"页，共"+result.extend.page.pages+"页,一共"+result.extend.page.total+"条记录");
    	totalRecord=result.extend.page.total;
    }
    
    function build_page_nav(result){
    	$("#page_info_nav").empty();
    	var ul=$("<ul></ul>").addClass("pagination");
    	var firstPage=$("<li></li>").append($("<a></a>").append("首页").attr("href","javascript:return false;"));
    	var prePage=$("<li></li>").append($("<a></a>").append("上一页"));
		if(result.extend.page.hasPreviousPage==false){
			firstPage.addClass("disabled");  
			prePage.addClass("prePage");
    	}
		firstPage.click(function(){
			if(result.extend.page.isFirstPage){
				
				return;
			}
			toPage(1);
		});
		prePage.click(function(){
			if(result.extend.page.pageNum==1){
				toPage(1);
			}else{
				toPage(result.extend.page.pageNum-1);
			}
			
		});
    	var nextPage=$("<li></li>").append($("<a></a>").append("下一页"));
    	var lastPage=$("<li></li>").append($("<a></a>").append("尾页").attr("href","javascript:return false;"));
    	console.log(result.extend.page.hasNextPage);
    	if(result.extend.page.hasNextPage==false){
    		nextPage.addClass("prePage");  
    		lastPage.addClass("disabled");
    	}
    	
    	lastPage.click(function(){
    		if(result.extend.page.isLastPage){
    			return;
    		}
			toPage(result.extend.page.pages);
		});
    	nextPage.click(function(){
    		if(result.extend.page.pageNum==result.extend.page.pages){
    			toPage(result.extend.page.pages);
    		}else{
    			toPage(result.extend.page.pageNum+1);
    		}
			
		});
    	ul.append(firstPage).append(prePage);
    	$.each(result.extend.page.navigatepageNums,function(index,item){
    		var numLi=$("<li></li>").append($("<a></a>").append(item));
    		if(result.extend.page.pageNum==item){
    			numLi.addClass("active");
    		}
    		numLi.click(function(){
    			toPage(item);
    		});
    		ul.append(numLi);
    	});
    	ul.append(nextPage).append(lastPage);
    	var navElv=$("<nv></nv>").append(ul);
    	navElv.appendTo("#page_info_nav");
    }
    //访问用户的gitee主页
    function visitGitee(userId){
    	console.log(userId);
    	$.get("${pageContext.request.contextPath}/git/getGiteePage.do?userId="+userId)
    		.done(function(result){
    			console.log(result);
    			if(result.code==100){
    				var url=result.extend.url;
    				console.log(userId+":"+url);
    				window.open(url);
    			}else{
    				layer.msg(result.extend.msg, {icon: 5});
    			}
    		});
    }
    //展现用户的gitee代码提交情况
    function showGiteePush(userId,projectId){
    	//先判断用户是否授权
    	$.get("${pageContext.request.contextPath}/git/isInGiteePro.do?userId="+userId+"&projectId="+projectId)
    		.done(function(result){
    			console.log("showGiteePush");
    			console.log(result);
    			if(result.code==200){
    				layer.msg(result.extend.msg, {icon: 5});
    				return;
    			}else{
    				//打开页面
    		    	layer.open({
    		  	      type: 2,
    		  	      title:['代码提交信息','font-size:18px;'],
    		  	      maxmin: true,
    		  	      shadeClose: true, //点击遮罩关闭层
    		  	      area : ['800px' , '600px'],
    		  	      content: '${pageContext.request.contextPath}/git/showGiteePush.do?userId='+userId+'&projectId='+projectId
    		  	    });
    			}
    		});
    	
    }
</script>
  </body>
</html>
